package org.example;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.*;
import com.deepoove.poi.data.style.PictureStyle;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.documents.DocumentObjectType;
import com.spire.doc.fields.DocPicture;
import com.spire.doc.interfaces.ICompositeObject;
import com.spire.doc.interfaces.IDocumentObject;

public class Demo01 {
    public static void main(String[] args) throws IOException {
        addGraph2();
    }

    // 添加段落
    public static void addGraph() throws IOException {
        String text = "this a paragraph";
        DocumentRenderData data = Documents.of().addParagraph(Paragraphs.of(text).create()).create();
        XWPFTemplate template = XWPFTemplate.create(data);
        template.write(new FileOutputStream("d:/output.docx"));
    }

    // 添加图片
    public static void addGraph2() throws IOException {
        String text = "this a paragraph";

        // 创建段落
        Paragraphs.ParagraphBuilder paragraphBuilder = Paragraphs.of();

        // 添加文字
        TextRenderData textRenderData = new TextRenderData();
        textRenderData.setText("这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容");
        paragraphBuilder.addText(textRenderData);


        // 添加图片
        String picBase64 = FileUtils.readFileToString(new File("d:/pic.txt"));
        PictureRenderData onePic = Pictures.ofBase64(picBase64, PictureType.BMP).create();

        PictureStyle pictureStyle = new PictureStyle();
        pictureStyle.setAlign(PictureStyle.PictureAlign.CENTER);
        pictureStyle.setWidth(600);
        pictureStyle.setHeight(300);
        onePic.setPictureStyle(pictureStyle);

        paragraphBuilder.addPicture(onePic);


        RowRenderData row0 = Rows.of("姓名", "学历").textColor("FFFFFF")
                .bgColor("4472C4").center().create();
        RowRenderData row1 = Rows.create("李四", "博士");
        TableRenderData tableRenderData = Tables.create(row0, row1);


        Documents.DocumentBuilder documentBuilder = Documents.of();
        // 添加段落
        documentBuilder.addParagraph(paragraphBuilder.create());
        // 添加表格
        documentBuilder.addTable(tableRenderData);
        DocumentRenderData data = documentBuilder.create();

        XWPFTemplate template = XWPFTemplate.create(data);
        template.write(new FileOutputStream("d:/output.docx"));
    }
}